package com.liyujie.dyeingmachine.ui.home;

import androidx.databinding.ObservableField;
import androidx.lifecycle.ViewModel;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.SPUtils;
import com.liyujie.dyeingmachine.ui.backstage.BackstageActivity;
import com.liyujie.dyeingmachine.ui.home.operate.OperationPageActivity;
import com.liyujie.dyeingmachine.views.passlibrary.PayPassDialog;
import com.liyujie.dyeingmachine.views.passlibrary.PayPassView;

public class HomeViewModel extends ViewModel {

    /**
     * 版本号
     */
    public final ObservableField<String> VersionNumber = new ObservableField<>();

    /**
     * 初始化
     */
    public void initializeViewModel() {
        VersionNumber.set("V:" + AppUtils.getAppVersionName());

    }


    /**
     * 后台设置
     */
    public void BackgroundSetting() {

    }

    /**
     * 开始页面
     */
    public void StartPage() {
        /**
         * 操作页面
         */
        ActivityUtils.startActivity(OperationPageActivity.class);
    }

    /**
     * 系统管理
     */
    public void SystemManagement() {
        PayPassDialog payPassDialog = new PayPassDialog(ActivityUtils.getTopActivity());
        payPassDialog.getPayViewPass().setPayClickListener(new PayPassView.OnPayClickListener() {
            @Override
            public void onPassFinish(String password) {
                //关闭回调
                payPassDialog.dismiss();
                if (password.equals(SPUtils.getInstance().getString("managementPassword", "123456"))) {
                    /**
                     * 系统管理
                     */
                    ActivityUtils.startActivity(BackstageActivity.class);
                    /**
                     * 关闭
                     */
                    ActivityUtils.finishActivity(HomeActivity.class);
                }
            }

            @Override
            public void onPayClose() {
                //关闭回调
                payPassDialog.dismiss();
            }
        });
        if (null != payPassDialog) {
            payPassDialog.show();
        }
    }

}
